//////////////////////////////////////////////
/// CALCULADORA PARA CEGOS
/// 
/// Gestão de Projecto de Software 2013-2014
///
/// Grupo 14:
/// Diogo Moita - 21170937
/// Diogo Oliveira - 21180842
/// Luís Monteiro - 21170270
/// Luís Costa - 21210392
/// Nuno Aguiar - 21160515
/// Pedro Marques - 21160524
//////////////////////////////////////////////
package cvi;

import java.awt.KeyEventDispatcher;
import java.awt.KeyboardFocusManager;
import java.awt.event.KeyEvent;
import javax.swing.ImageIcon;

public class GUI extends javax.swing.JFrame {

    static CVI cvi;

    private class MyDispatcher implements KeyEventDispatcher {

        @Override
        public boolean dispatchKeyEvent(KeyEvent e) {
            if (e.getID() == KeyEvent.KEY_PRESSED) {
                switch (e.getKeyCode()) {

                    case KeyEvent.VK_1:
                        b_1MouseClicked(null);
                        break;

                    case KeyEvent.VK_NUMPAD1:
                        b_1MouseClicked(null);
                        break;

                    case KeyEvent.VK_2:
                        b_2MouseClicked(null);
                        break;

                    case KeyEvent.VK_NUMPAD2:
                        b_2MouseClicked(null);
                        break;

                    case KeyEvent.VK_3:
                        b_3MouseClicked(null);
                        break;

                    case KeyEvent.VK_NUMPAD3:
                        b_3MouseClicked(null);
                        break;

                    case KeyEvent.VK_4:
                        b_4MouseClicked(null);
                        break;

                    case KeyEvent.VK_NUMPAD4:
                        b_4MouseClicked(null);
                        break;

                    case KeyEvent.VK_5:
                        b_5MouseClicked(null);
                        break;

                    case KeyEvent.VK_NUMPAD5:
                        b_5MouseClicked(null);
                        break;

                    case KeyEvent.VK_6:
                        b_6MouseClicked(null);
                        break;

                    case KeyEvent.VK_NUMPAD6:
                        b_6MouseClicked(null);
                        break;

                    case KeyEvent.VK_7:
                        b_7MouseClicked(null);
                        break;

                    case KeyEvent.VK_NUMPAD7:
                        b_7MouseClicked(null);
                        break;

                    case KeyEvent.VK_8:
                        b_8MouseClicked(null);
                        break;

                    case KeyEvent.VK_NUMPAD8:
                        b_8MouseClicked(null);
                        break;

                    case KeyEvent.VK_9:
                        b_9MouseClicked(null);
                        break;

                    case KeyEvent.VK_NUMPAD9:
                        b_9MouseClicked(null);
                        break;

                    case KeyEvent.VK_0:
                        b_0MouseClicked(null);
                        break;

                    case KeyEvent.VK_NUMPAD0:
                        b_0MouseClicked(null);
                        break;

                    case KeyEvent.VK_PLUS:
                        b_maisMouseClicked(null);
                        break;
                    case KeyEvent.VK_ADD:
                        b_maisMouseClicked(null);
                        break;

                    case KeyEvent.VK_SUBTRACT:
                        b_menosMouseClicked(null);
                        break;
                    case KeyEvent.VK_MINUS:
                        b_menosMouseClicked(null);
                        break;

                    case KeyEvent.VK_MULTIPLY:
                        b_multiMouseClicked(null);
                        break;
                    case KeyEvent.VK_ASTERISK:
                        b_multiMouseClicked(null);
                        break;

                    case KeyEvent.VK_DIVIDE:
                        b_divMouseClicked(null);
                        break;
                    case KeyEvent.VK_SLASH:
                        b_divMouseClicked(null);
                        break;

                    // +/-
                    case KeyEvent.VK_T:
                        b_trocaMouseClicked(null);
                        break;

                    // Quadrado
                    case KeyEvent.VK_Q:
                        b_quadMouseClicked(null);
                        break;

                    // Raiz quadrada
                    case KeyEvent.VK_R:
                        b_raizMouseClicked(null);
                        break;

                    // ponto
                    case KeyEvent.VK_PERIOD:
                        b_pontoMouseClicked(null);
                        break;

                    // Apagar
                    case KeyEvent.VK_BACK_SPACE:
                        b_apagarMouseClicked(null);
                        break;
                    case KeyEvent.VK_DELETE:
                        b_apagarMouseClicked(null);
                        break;

                    // Clear
                    case KeyEvent.VK_C:
                        b_cMouseClicked(null);
                        break;
                    case KeyEvent.VK_CLEAR:
                        b_apagarMouseClicked(null);
                        break;

                    // Igual
                    case KeyEvent.VK_ENTER:
                        b_igualMouseClicked(null);
                        break;
                    case KeyEvent.VK_EQUALS:
                        b_igualMouseClicked(null);
                        break;

                    // Percentagem
                    case KeyEvent.VK_P:
                        b_percMouseClicked(null);
                        break;
                        
                        // Dar um aviso
                    default:
                        cvi.avisar();
                        break;
                }
            }
            return false;
        }
    }

    public GUI() {
        initComponents();
        cvi = new CVI(t_output, t_op);
        KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
        manager.addKeyEventDispatcher(new MyDispatcher());
        jPanel3.requestFocus();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        t_output = new javax.swing.JTextField();
        t_op = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        b_1 = new javax.swing.JButton();
        b_2 = new javax.swing.JButton();
        b_3 = new javax.swing.JButton();
        b_4 = new javax.swing.JButton();
        b_5 = new javax.swing.JButton();
        b_6 = new javax.swing.JButton();
        b_7 = new javax.swing.JButton();
        b_8 = new javax.swing.JButton();
        b_9 = new javax.swing.JButton();
        b_0 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        b_c = new javax.swing.JButton();
        b_apagar = new javax.swing.JButton();
        b_mais = new javax.swing.JButton();
        b_menos = new javax.swing.JButton();
        b_multi = new javax.swing.JButton();
        b_div = new javax.swing.JButton();
        b_ponto = new javax.swing.JButton();
        b_troca = new javax.swing.JButton();
        b_raiz = new javax.swing.JButton();
        b_quad = new javax.swing.JButton();
        b_perc = new javax.swing.JButton();
        b_igual = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Calculadora para Cegos");
        setFont(new java.awt.Font("Monospaced", 1, 24)); // NOI18N
        setIconImage(new ImageIcon(getClass().getResource("/cvi/resources/calc.png")).getImage());
        setMinimumSize(new java.awt.Dimension(800, 600));
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                formComponentResized(evt);
            }
        });
        getContentPane().setLayout(new java.awt.GridLayout(0, 1));

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setAlignmentX(0.0F);
        jPanel1.setAlignmentY(0.0F);
        jPanel1.setMinimumSize(new java.awt.Dimension(800, 200));
        jPanel1.setPreferredSize(new java.awt.Dimension(800, 200));

        t_output.setEditable(false);
        t_output.setBackground(new java.awt.Color(255, 255, 255));
        t_output.setFont(new java.awt.Font("Monospaced", 0, 120)); // NOI18N
        t_output.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        t_output.setText("-8888.8888");

        t_op.setEditable(false);
        t_op.setBackground(new java.awt.Color(255, 255, 255));
        t_op.setFont(new java.awt.Font("Monospaced", 1, 100)); // NOI18N
        t_op.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        t_op.setText("+");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(t_output, javax.swing.GroupLayout.DEFAULT_SIZE, 716, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(t_op, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(t_output, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
            .addComponent(t_op)
        );

        getContentPane().add(jPanel1);

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setForeground(new java.awt.Color(255, 255, 255));
        jPanel2.setAlignmentX(0.0F);
        jPanel2.setAlignmentY(0.0F);
        jPanel2.setFont(new java.awt.Font("Monospaced", 1, 24)); // NOI18N
        jPanel2.setMinimumSize(new java.awt.Dimension(800, 200));
        jPanel2.setPreferredSize(new java.awt.Dimension(800, 200));
        jPanel2.setLayout(new java.awt.GridLayout(1, 0));

        b_1.setBackground(new java.awt.Color(204, 204, 204));
        b_1.setFont(new java.awt.Font("Monospaced", 1, 80)); // NOI18N
        b_1.setText("1");
        b_1.setAlignmentY(0.0F);
        b_1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        b_1.setMargin(new java.awt.Insets(0, 0, 0, 0));
        b_1.setMinimumSize(new java.awt.Dimension(0, 0));
        b_1.setPreferredSize(new java.awt.Dimension(0, 0));
        b_1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                b_1MouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                b_1MouseEntered(evt);
            }
        });
        jPanel2.add(b_1);

        b_2.setBackground(new java.awt.Color(102, 102, 102));
        b_2.setFont(new java.awt.Font("Monospaced", 1, 80)); // NOI18N
        b_2.setForeground(new java.awt.Color(255, 255, 255));
        b_2.setAlignmentY(0.0F);
        b_2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        b_2.setLabel("2");
        b_2.setMargin(new java.awt.Insets(0, 0, 0, 0));
        b_2.setMinimumSize(new java.awt.Dimension(0, 0));
        b_2.setPreferredSize(new java.awt.Dimension(0, 0));
        b_2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                b_2MouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                b_2MouseEntered(evt);
            }
        });
        jPanel2.add(b_2);

        b_3.setBackground(new java.awt.Color(204, 204, 204));
        b_3.setFont(new java.awt.Font("Monospaced", 1, 80)); // NOI18N
        b_3.setText("3");
        b_3.setAlignmentY(0.0F);
        b_3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        b_3.setMargin(new java.awt.Insets(0, 0, 0, 0));
        b_3.setMinimumSize(new java.awt.Dimension(0, 0));
        b_3.setPreferredSize(new java.awt.Dimension(0, 0));
        b_3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                b_3MouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                b_3MouseEntered(evt);
            }
        });
        jPanel2.add(b_3);

        b_4.setBackground(new java.awt.Color(102, 102, 102));
        b_4.setFont(new java.awt.Font("Monospaced", 1, 80)); // NOI18N
        b_4.setForeground(new java.awt.Color(255, 255, 255));
        b_4.setText("4");
        b_4.setAlignmentY(0.0F);
        b_4.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        b_4.setMargin(new java.awt.Insets(0, 0, 0, 0));
        b_4.setMinimumSize(new java.awt.Dimension(0, 0));
        b_4.setPreferredSize(new java.awt.Dimension(0, 0));
        b_4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                b_4MouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                b_4MouseEntered(evt);
            }
        });
        jPanel2.add(b_4);

        b_5.setBackground(new java.awt.Color(204, 204, 204));
        b_5.setFont(new java.awt.Font("Monospaced", 1, 80)); // NOI18N
        b_5.setText("5");
        b_5.setAlignmentY(0.0F);
        b_5.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        b_5.setMargin(new java.awt.Insets(0, 0, 0, 0));
        b_5.setMinimumSize(new java.awt.Dimension(0, 0));
        b_5.setPreferredSize(new java.awt.Dimension(0, 0));
        b_5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                b_5MouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                b_5MouseEntered(evt);
            }
        });
        jPanel2.add(b_5);

        b_6.setBackground(new java.awt.Color(102, 102, 102));
        b_6.setFont(new java.awt.Font("Monospaced", 1, 80)); // NOI18N
        b_6.setForeground(new java.awt.Color(255, 255, 255));
        b_6.setText("6");
        b_6.setAlignmentY(0.0F);
        b_6.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        b_6.setMargin(new java.awt.Insets(0, 0, 0, 0));
        b_6.setMinimumSize(new java.awt.Dimension(0, 0));
        b_6.setPreferredSize(new java.awt.Dimension(0, 0));
        b_6.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                b_6MouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                b_6MouseEntered(evt);
            }
        });
        jPanel2.add(b_6);

        b_7.setBackground(new java.awt.Color(204, 204, 204));
        b_7.setFont(new java.awt.Font("Monospaced", 1, 80)); // NOI18N
        b_7.setText("7");
        b_7.setAlignmentY(0.0F);
        b_7.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        b_7.setMargin(new java.awt.Insets(0, 0, 0, 0));
        b_7.setMinimumSize(new java.awt.Dimension(0, 0));
        b_7.setPreferredSize(new java.awt.Dimension(0, 0));
        b_7.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                b_7MouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                b_7MouseEntered(evt);
            }
        });
        jPanel2.add(b_7);

        b_8.setBackground(new java.awt.Color(102, 102, 102));
        b_8.setFont(new java.awt.Font("Monospaced", 1, 80)); // NOI18N
        b_8.setForeground(new java.awt.Color(255, 255, 255));
        b_8.setText("8");
        b_8.setAlignmentY(0.0F);
        b_8.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        b_8.setMargin(new java.awt.Insets(0, 0, 0, 0));
        b_8.setMinimumSize(new java.awt.Dimension(0, 0));
        b_8.setPreferredSize(new java.awt.Dimension(0, 0));
        b_8.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                b_8MouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                b_8MouseEntered(evt);
            }
        });
        jPanel2.add(b_8);

        b_9.setBackground(new java.awt.Color(204, 204, 204));
        b_9.setFont(new java.awt.Font("Monospaced", 1, 80)); // NOI18N
        b_9.setText("9");
        b_9.setAlignmentY(0.0F);
        b_9.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        b_9.setMargin(new java.awt.Insets(0, 0, 0, 0));
        b_9.setMinimumSize(new java.awt.Dimension(0, 0));
        b_9.setPreferredSize(new java.awt.Dimension(0, 0));
        b_9.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                b_9MouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                b_9MouseEntered(evt);
            }
        });
        jPanel2.add(b_9);

        b_0.setBackground(new java.awt.Color(102, 102, 102));
        b_0.setFont(new java.awt.Font("Monospaced", 1, 80)); // NOI18N
        b_0.setForeground(new java.awt.Color(255, 255, 255));
        b_0.setText("0");
        b_0.setAlignmentY(0.0F);
        b_0.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        b_0.setMargin(new java.awt.Insets(0, 0, 0, 0));
        b_0.setMinimumSize(new java.awt.Dimension(0, 0));
        b_0.setPreferredSize(new java.awt.Dimension(0, 0));
        b_0.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                b_0MouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                b_0MouseEntered(evt);
            }
        });
        jPanel2.add(b_0);

        getContentPane().add(jPanel2);

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));
        jPanel3.setAlignmentX(0.0F);
        jPanel3.setAlignmentY(0.0F);
        jPanel3.setMinimumSize(new java.awt.Dimension(800, 200));
        jPanel3.setPreferredSize(new java.awt.Dimension(800, 200));
        jPanel3.setLayout(new java.awt.GridLayout(1, 0));

        b_c.setBackground(new java.awt.Color(204, 255, 204));
        b_c.setFont(new java.awt.Font("Monospaced", 1, 50)); // NOI18N
        b_c.setText("C");
        b_c.setAlignmentY(0.0F);
        b_c.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        b_c.setMargin(new java.awt.Insets(0, 0, 0, 0));
        b_c.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                b_cMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                b_cMouseEntered(evt);
            }
        });
        jPanel3.add(b_c);

        b_apagar.setBackground(new java.awt.Color(102, 255, 102));
        b_apagar.setFont(new java.awt.Font("Monospaced", 1, 50)); // NOI18N
        b_apagar.setText("<");
        b_apagar.setAlignmentY(0.0F);
        b_apagar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        b_apagar.setMargin(new java.awt.Insets(0, 0, 0, 0));
        b_apagar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                b_apagarMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                b_apagarMouseEntered(evt);
            }
        });
        jPanel3.add(b_apagar);

        b_mais.setBackground(new java.awt.Color(255, 255, 102));
        b_mais.setFont(new java.awt.Font("Monospaced", 1, 50)); // NOI18N
        b_mais.setText("+");
        b_mais.setAlignmentY(0.0F);
        b_mais.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        b_mais.setMargin(new java.awt.Insets(0, 0, 0, 0));
        b_mais.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                b_maisMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                b_maisMouseEntered(evt);
            }
        });
        jPanel3.add(b_mais);

        b_menos.setBackground(new java.awt.Color(204, 204, 0));
        b_menos.setFont(new java.awt.Font("Monospaced", 1, 50)); // NOI18N
        b_menos.setText("-");
        b_menos.setAlignmentY(0.0F);
        b_menos.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        b_menos.setMargin(new java.awt.Insets(0, 0, 0, 0));
        b_menos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                b_menosMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                b_menosMouseEntered(evt);
            }
        });
        jPanel3.add(b_menos);

        b_multi.setBackground(new java.awt.Color(255, 255, 102));
        b_multi.setFont(new java.awt.Font("Monospaced", 1, 50)); // NOI18N
        b_multi.setText("X");
        b_multi.setAlignmentY(0.0F);
        b_multi.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        b_multi.setMargin(new java.awt.Insets(0, 0, 0, 0));
        b_multi.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                b_multiMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                b_multiMouseEntered(evt);
            }
        });
        jPanel3.add(b_multi);

        b_div.setBackground(new java.awt.Color(204, 204, 0));
        b_div.setFont(new java.awt.Font("Monospaced", 1, 50)); // NOI18N
        b_div.setText("/");
        b_div.setAlignmentY(0.0F);
        b_div.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        b_div.setMargin(new java.awt.Insets(0, 0, 0, 0));
        b_div.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                b_divMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                b_divMouseEntered(evt);
            }
        });
        jPanel3.add(b_div);

        b_ponto.setBackground(new java.awt.Color(102, 102, 102));
        b_ponto.setFont(new java.awt.Font("Monospaced", 1, 50)); // NOI18N
        b_ponto.setForeground(new java.awt.Color(255, 255, 255));
        b_ponto.setText(".");
        b_ponto.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        b_ponto.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                b_pontoMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                b_pontoMouseEntered(evt);
            }
        });
        jPanel3.add(b_ponto);

        b_troca.setBackground(new java.awt.Color(204, 204, 204));
        b_troca.setFont(new java.awt.Font("Monospaced", 1, 48)); // NOI18N
        b_troca.setText("±");
        b_troca.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        b_troca.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                b_trocaMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                b_trocaMouseEntered(evt);
            }
        });
        jPanel3.add(b_troca);

        b_raiz.setBackground(new java.awt.Color(102, 102, 102));
        b_raiz.setFont(new java.awt.Font("Monospaced", 1, 44)); // NOI18N
        b_raiz.setForeground(new java.awt.Color(255, 255, 255));
        b_raiz.setText("√");
        b_raiz.setAlignmentY(0.0F);
        b_raiz.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        b_raiz.setMargin(new java.awt.Insets(0, 0, 0, 0));
        b_raiz.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                b_raizMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                b_raizMouseEntered(evt);
            }
        });
        jPanel3.add(b_raiz);

        b_quad.setBackground(new java.awt.Color(204, 204, 204));
        b_quad.setFont(new java.awt.Font("Monospaced", 1, 32)); // NOI18N
        b_quad.setText("x²");
        b_quad.setAlignmentY(0.0F);
        b_quad.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        b_quad.setMargin(new java.awt.Insets(0, 0, 0, 0));
        b_quad.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                b_quadMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                b_quadMouseEntered(evt);
            }
        });
        jPanel3.add(b_quad);

        b_perc.setBackground(new java.awt.Color(102, 102, 102));
        b_perc.setFont(new java.awt.Font("Monospaced", 1, 50)); // NOI18N
        b_perc.setForeground(new java.awt.Color(255, 255, 255));
        b_perc.setText("%");
        b_perc.setAlignmentY(0.0F);
        b_perc.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        b_perc.setMargin(new java.awt.Insets(0, 0, 0, 0));
        b_perc.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                b_percMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                b_percMouseEntered(evt);
            }
        });
        jPanel3.add(b_perc);

        b_igual.setBackground(new java.awt.Color(204, 255, 204));
        b_igual.setFont(new java.awt.Font("Monospaced", 1, 50)); // NOI18N
        b_igual.setText("=");
        b_igual.setAlignmentY(0.0F);
        b_igual.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        b_igual.setMargin(new java.awt.Insets(0, 0, 0, 0));
        b_igual.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                b_igualMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                b_igualMouseEntered(evt);
            }
        });
        jPanel3.add(b_igual);

        getContentPane().add(jPanel3);

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void b_1MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_1MouseEntered
        cvi.sobreBotao('1');
    }//GEN-LAST:event_b_1MouseEntered

    private void b_2MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_2MouseEntered
        cvi.sobreBotao('2');
    }//GEN-LAST:event_b_2MouseEntered

    private void b_3MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_3MouseEntered
        cvi.sobreBotao('3');
    }//GEN-LAST:event_b_3MouseEntered

    private void b_8MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_8MouseEntered
        cvi.sobreBotao('8');
    }//GEN-LAST:event_b_8MouseEntered

    private void b_7MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_7MouseEntered
        cvi.sobreBotao('7');
    }//GEN-LAST:event_b_7MouseEntered

    private void b_6MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_6MouseEntered
        cvi.sobreBotao('6');
    }//GEN-LAST:event_b_6MouseEntered

    private void b_5MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_5MouseEntered
        cvi.sobreBotao('5');
    }//GEN-LAST:event_b_5MouseEntered

    private void b_4MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_4MouseEntered
        cvi.sobreBotao('4');
    }//GEN-LAST:event_b_4MouseEntered

    private void b_9MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_9MouseEntered
        cvi.sobreBotao('9');
    }//GEN-LAST:event_b_9MouseEntered

    private void b_0MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_0MouseEntered
        cvi.sobreBotao('0');
    }//GEN-LAST:event_b_0MouseEntered

    private void b_cMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_cMouseEntered
        cvi.sobreBotao('C');
    }//GEN-LAST:event_b_cMouseEntered

    private void b_apagarMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_apagarMouseEntered
        cvi.sobreBotao('D');
    }//GEN-LAST:event_b_apagarMouseEntered

    private void b_maisMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_maisMouseEntered
        cvi.sobreBotao('+');
    }//GEN-LAST:event_b_maisMouseEntered

    private void b_menosMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_menosMouseEntered
        cvi.sobreBotao('-');
    }//GEN-LAST:event_b_menosMouseEntered

    private void b_multiMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_multiMouseEntered
        cvi.sobreBotao('*');
    }//GEN-LAST:event_b_multiMouseEntered

    private void b_divMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_divMouseEntered
        cvi.sobreBotao('/');
    }//GEN-LAST:event_b_divMouseEntered

    private void b_trocaMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_trocaMouseEntered
        cvi.sobreBotao('T');
    }//GEN-LAST:event_b_trocaMouseEntered

    private void b_raizMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_raizMouseEntered
        cvi.sobreBotao('R');
    }//GEN-LAST:event_b_raizMouseEntered

    private void b_quadMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_quadMouseEntered
        cvi.sobreBotao('Q');
    }//GEN-LAST:event_b_quadMouseEntered

    private void b_percMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_percMouseEntered
        cvi.sobreBotao('%');
    }//GEN-LAST:event_b_percMouseEntered

    private void b_igualMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_igualMouseEntered
        cvi.sobreBotao('=');
    }//GEN-LAST:event_b_igualMouseEntered

    private void b_1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_1MouseClicked
        if (evt == null) {
            cvi.clickBotao('1', true);
        } else {
            cvi.clickBotao('1', false);
        }
    }//GEN-LAST:event_b_1MouseClicked

    private void b_2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_2MouseClicked
        if (evt == null) {
            cvi.clickBotao('2', true);
        } else {
            cvi.clickBotao('2', false);
        }
    }//GEN-LAST:event_b_2MouseClicked

    private void b_3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_3MouseClicked
        if (evt == null) {
            cvi.clickBotao('3', true);
        } else {
            cvi.clickBotao('3', false);
        }
    }//GEN-LAST:event_b_3MouseClicked

    private void b_4MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_4MouseClicked
        if (evt == null) {
            cvi.clickBotao('4', true);
        } else {
            cvi.clickBotao('4', false);
        }
    }//GEN-LAST:event_b_4MouseClicked

    private void b_5MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_5MouseClicked
        if (evt == null) {
            cvi.clickBotao('5', true);
        } else {
            cvi.clickBotao('5', false);
        }
    }//GEN-LAST:event_b_5MouseClicked

    private void b_6MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_6MouseClicked
        if (evt == null) {
            cvi.clickBotao('6', true);
        } else {
            cvi.clickBotao('6', false);
        }
    }//GEN-LAST:event_b_6MouseClicked

    private void b_7MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_7MouseClicked
        if (evt == null) {
            cvi.clickBotao('7', true);
        } else {
            cvi.clickBotao('7', false);
        }
    }//GEN-LAST:event_b_7MouseClicked

    private void b_8MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_8MouseClicked
        if (evt == null) {
            cvi.clickBotao('8', true);
        } else {
            cvi.clickBotao('8', false);
        }
    }//GEN-LAST:event_b_8MouseClicked

    private void b_9MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_9MouseClicked
        if (evt == null) {
            cvi.clickBotao('9', true);
        } else {
            cvi.clickBotao('9', false);
        }
    }//GEN-LAST:event_b_9MouseClicked

    private void b_0MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_0MouseClicked
        if (evt == null) {
            cvi.clickBotao('0', true);
        } else {
            cvi.clickBotao('0', false);
        }
    }//GEN-LAST:event_b_0MouseClicked

    private void b_cMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_cMouseClicked
        if (evt == null) {
            cvi.clickBotao('C', true);
        } else {
            cvi.clickBotao('C', false);
        }
    }//GEN-LAST:event_b_cMouseClicked

    private void b_apagarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_apagarMouseClicked
        if (evt == null) {
            cvi.clickBotao('D', true);
        } else {
            cvi.clickBotao('D', false);
        }
    }//GEN-LAST:event_b_apagarMouseClicked

    private void b_maisMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_maisMouseClicked
        if (evt == null) {
            cvi.clickBotao('+', true);
        } else {
            cvi.clickBotao('+', false);
        }
    }//GEN-LAST:event_b_maisMouseClicked

    private void b_menosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_menosMouseClicked
        if (evt == null) {
            cvi.clickBotao('-', true);
        } else {
            cvi.clickBotao('-', false);
        }
    }//GEN-LAST:event_b_menosMouseClicked

    private void b_multiMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_multiMouseClicked
        if (evt == null) {
            cvi.clickBotao('*', true);
        } else {
            cvi.clickBotao('*', false);
        }
    }//GEN-LAST:event_b_multiMouseClicked

    private void b_divMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_divMouseClicked
        if (evt == null) {
            cvi.clickBotao('/', true);
        } else {
            cvi.clickBotao('/', false);
        }
    }//GEN-LAST:event_b_divMouseClicked

    private void b_pontoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_pontoMouseClicked
        if (evt == null) {
            cvi.clickBotao('.', true);
        } else {
            cvi.clickBotao('.', false);
        }
    }//GEN-LAST:event_b_pontoMouseClicked

    private void b_trocaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_trocaMouseClicked
        if (evt == null) {
            cvi.clickBotao('T', true);
        } else {
            cvi.clickBotao('T', false);
        }
    }//GEN-LAST:event_b_trocaMouseClicked

    private void b_raizMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_raizMouseClicked
        if (evt == null) {
            cvi.clickBotao('R', true);
        } else {
            cvi.clickBotao('R', false);
        }
    }//GEN-LAST:event_b_raizMouseClicked

    private void b_quadMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_quadMouseClicked
        if (evt == null) {
            cvi.clickBotao('Q', true);
        } else {
            cvi.clickBotao('Q', false);
        }
    }//GEN-LAST:event_b_quadMouseClicked

    private void b_percMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_percMouseClicked
        if (evt == null) {
            cvi.clickBotao('%', true);
        } else {
            cvi.clickBotao('%', false);
        }
    }//GEN-LAST:event_b_percMouseClicked

    private void b_igualMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_igualMouseClicked
        if (evt == null) {
            cvi.clickBotao('=', true);
        } else {
            cvi.clickBotao('=', false);
        }
    }//GEN-LAST:event_b_igualMouseClicked

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        cvi.exit();
    }//GEN-LAST:event_formWindowClosing

    private void formComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentResized
        // ALTERAR TAMANHO DA LETRA AQUI
        // b_c.setFont(b_c.getFont().deriveFont((float)(b_c.getWidth()/2)));       
    }//GEN-LAST:event_formComponentResized

    private void b_pontoMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_b_pontoMouseEntered
        cvi.sobreBotao('.');
    }//GEN-LAST:event_b_pontoMouseEntered

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new GUI().setVisible(true);
            }
        });
    }

    public void invocaBotoes(int t) {
        switch (t) {
            case KeyEvent.VK_1:
                b_1MouseClicked(null);
                break;
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton b_0;
    private javax.swing.JButton b_1;
    private javax.swing.JButton b_2;
    private javax.swing.JButton b_3;
    private javax.swing.JButton b_4;
    private javax.swing.JButton b_5;
    private javax.swing.JButton b_6;
    private javax.swing.JButton b_7;
    private javax.swing.JButton b_8;
    private javax.swing.JButton b_9;
    private javax.swing.JButton b_apagar;
    private javax.swing.JButton b_c;
    private javax.swing.JButton b_div;
    private javax.swing.JButton b_igual;
    private javax.swing.JButton b_mais;
    private javax.swing.JButton b_menos;
    private javax.swing.JButton b_multi;
    private javax.swing.JButton b_perc;
    private javax.swing.JButton b_ponto;
    private javax.swing.JButton b_quad;
    private javax.swing.JButton b_raiz;
    private javax.swing.JButton b_troca;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JTextField t_op;
    private javax.swing.JTextField t_output;
    // End of variables declaration//GEN-END:variables
}
